﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using CustomsSystem.BLL;
using CustomsSystem.Model;
using Maticsoft.Common;


namespace WEB.Emp
{
    public partial class ChanceEmp : System.Web.UI.Page
    {
        DataSet ds;
        EmpManage empMan = new EmpManage();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                JobManage job = new JobManage();
                DropDownList1.DataSource = job.GetAllList();
                DropDownList1.DataTextField = "JobName";
                DropDownList1.DataValueField = "JobNo";
                DropDownList1.DataBind();

                if (Request.QueryString["empnum"] != null)
                {
                    string EmpNum = Convert.ToString(Request.QueryString["empnum"]);
                    string jobno = Session["jobno"].ToString();
                    Info_emp EMPmo = empMan.GetModel(EmpNum);
                    Label5.Text = EMPmo.JobNo;
                    DropDownList1.Text = Label5.Text;
                    Label6.Text = EMPmo.EmpNum;
                    TextBox2.Text = EMPmo.UserName;
                    TextBox3.Text = EMPmo.PassWord;
                    TextBox5.Text = EMPmo.Remarks;
                }
            }
            Label5.Text = DropDownList1.Text;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox4.Text != TextBox3.Text)
            {
                Response.Write("<Script>alert('密码不对，请重新输入!')</script>");
                TextBox3.Text = string.Empty;
                TextBox4.Text = string.Empty;
            }
            else
            {
                Info_emp chanmo = new Info_emp();
                chanmo.JobNo = Label5.Text;
                chanmo.EmpNum = Label6.Text;
                chanmo.UserName = TextBox2.Text;
                chanmo.PassWord =stringpro .md5(TextBox3.Text);
                chanmo.Remarks = TextBox5.Text;
                if (empMan.Update(chanmo))
                {
                    string jobno = Session["jobno"].ToString();
                    MessageBox.ShowAndRedirect(this, "修改成功", "EmpIndex.aspx?jobno="+jobno);
                }
                else Response.Write("<script>alert('未知原因导致修改失败！')</script>");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string jobno = Session["jobno"].ToString();
            Response.Redirect("EmpIndex.aspx?jobno="+jobno);
        }
    }
}